home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.03 Jul 92 / Matrix Parser / MatrixFunctions < prev    next >
Encoding:
Text File  |  1992-12-24  |  1.6 KB  |  90 lines  |  [TEXT/PJMM]

  1. unit MatrixFunctions;
  2.  
  3. interface
  4.  
  5.     uses
  6.  
  7.         Globals;
  8.  
  9.  
  10.     procedure matrixfunctions (var matrix: hdlsinglearraymatrix; var mrows, ncols: longint; var matrixoper: string30; var realresult: extended);
  11.  
  12.     procedure matrixtranspose (var matrix: hdlsinglearraymatrix; var mrows, ncols: longint; var matrixoper: string30);
  13.  
  14.  
  15. implementation
  16.  
  17.  
  18.     procedure matrixfunctions;
  19.  
  20.         var
  21.             i, a, b: longint;
  22.             bstring: str255;
  23.             x: extended;
  24.             showwind: boolean;
  25.  
  26.     begin
  27.  
  28.         matrix^^[1] := mrows;
  29.         matrix^^[2] := ncols;
  30.  
  31.         for i := 3 to mrows * ncols + 2 do
  32.             begin
  33.                 x := matrix^^[i];
  34.                 if matrixoper = 'ln' then
  35.                     x := ln(x);
  36.                 if matrixoper = 'log' then
  37.                     x := ln(x) / ln(10);
  38.                 if matrixoper = 'exp' then
  39.                     x := exp(x);
  40.                 if matrixoper = 'sin' then
  41.                     x := sin(x);
  42.                 if matrixoper = 'abs' then
  43.                     x := abs(x);
  44.                 if matrixoper = 'sqr' then
  45.                     x := sqr(x);
  46.                 if matrixoper = 'sqrt' then
  47.                     x := sqrt(x);
  48.                 if matrixoper = plus then
  49.                     x := x;
  50.                 if matrixoper = minus then
  51.                     x := -x;
  52.                 matrix^^[i] := x;
  53.             end;
  54.  
  55.     end;
  56.  
  57.     procedure matrixtranspose;
  58.  
  59.         var
  60.             i, j, l: longint;
  61.             dummatrix: hdlsinglearraymatrix;
  62.  
  63.     begin
  64.  
  65.         mrows := round(matrix^^[1]);
  66.         ncols := round(matrix^^[2]);
  67.  
  68.         blocksize := longint(10 * mrows * ncols + 20);
  69.         dummatrix := hdlsinglearraymatrix(NewHandle(blocksize));
  70.  
  71.         for i := 1 to mrows * ncols do
  72.             dummatrix^^[i] := matrix^^[2 + i];
  73.  
  74.         matrix^^[1] := ncols;
  75.         matrix^^[2] := mrows;
  76.  
  77.         l := 2;
  78.         for i := 1 to ncols do
  79.             for j := 1 to mrows do
  80.                 begin
  81.                     l := l + 1;
  82.                     matrix^^[l] := dummatrix^^[(j - 1) * ncols + i];
  83.                 end;
  84.  
  85.         DisposHandle(handle(dummatrix));
  86.  
  87.     end;
  88.  
  89.  
  90. end.